package com.zzyl.nursing.controller.member;
import com.zzyl.common.core.page.PageDomain;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.dto.DeviceDataDto;
import com.zzyl.nursing.dto.ElderDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberElderService;
import com.zzyl.nursing.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.service.IFamilyMemberService;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 老人家属Controller
 *
 * @author syl
 * @date 2025-05-30  member/user/login
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @Autowired
    private IFamilyMemberElderService familyMemberElderService;


    @PostMapping("/login")
    @ApiOperation("老人家属的登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult add(@RequestBody ElderDto elderDto){
        familyMemberService.add(elderDto);
        return AjaxResult.success();
    }


    @GetMapping("/my")
    @ApiOperation("查询家人列表")
    public AjaxResult queryFamilyList(){
        List<FamilyMemberElderVo> familyMemberElderVoList = familyMemberService.queryFamilyList();
        return AjaxResult.success(familyMemberElderVoList);
    }



    @GetMapping("/list-by-page")
    @ApiOperation("查看家人列表")
    public AjaxResult watchfamily(
            @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        List<FamilyMemberVO> familyMembers = familyMemberElderService.watchfamily(pageNum, pageSize);
        return success(familyMembers);
    }


    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询健康数据")
    public AjaxResult watchHealth(@PathVariable("iotId") String iotId) {
        List<DeviceDataVo> list = familyMemberService.watchHealth(iotId);
        return AjaxResult.success(list);
    }


    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation("按天统计查询指标数据")
    public  AjaxResult queryDeviceDataListByDay (DeviceDataDto dto) {
        List<DeviceDataVo> list = familyMemberService.queryDeviceDataListByDay(dto);
        List<DataVo> dataVoList = new ArrayList<>();
        for (DeviceDataVo deviceDataVo : list) {
            DataVo dataVo = new DataVo();
            dataVo.setDateTime(deviceDataVo.getDateTime());
            dataVo.setDataValue(deviceDataVo.getDataValue());
            dataVoList.add(dataVo);
        }
        return AjaxResult.success(dataVoList);
    }


    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation("按周统计查询指标数据")
    public  AjaxResult queryDeviceDataListByWeek (DeviceDataDto dto) {
        List<DataVo> list = familyMemberService.queryDeviceDataListByWeek(dto);
        return AjaxResult.success(list);

    }











}
